﻿using SpiderStudy.Utils.Currency;
using SpiderStudy.Utils.Currency.FileUtils;
using System;
using System.Collections.Generic;

namespace SpiderStudy.WebSite.DataHelper
{
    internal class DataClear
    {
        /// <summary>
        /// 清理数据，
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="ModeFlag">为TURE是是替换，FALSE跳过</param>
        public void FileClear(string FilePath, List<string> ExcludeList, bool ModeFlag)
        {
            List<string> TempList = new List<string>();
            foreach (string Line in FileHelper.ReadAllLine(FilePath))
            {
                String TempText = Line;
                foreach (string Key in ExcludeList)
                {
                    if (Line.IndexOf(Key) >= 0)
                    {
                        if (ModeFlag)
                        {
                            //替换模式，消除异常关键词
                            TempText.Replace(Key, "");
                        }
                        else

                        {
                            TempText = "";
                        }
                    }
                }

                TempList.Add(Line);
            }
            String SaveFilePath = new FileNameHelper().CreateFileNameAddTip(FilePath, "_去重");
            FileHelper.WriteUTF8List(SaveFilePath, ListHelper.ListRepeat(TempList));
        }
    }
}